home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / util / imagctlg.sit / Make Twin≈ ƒ / Partial Source / main.c next >
Encoding:
C/C++ Source or Header  |  1990-05-20  |  2.6 KB  |  124 lines  |  [TEXT/KAHL]

  1. /*
  2.  * utility to convert image types.
  3.  *
  4.  * WARNING WARNING WARNING WARNING WARNING WARNING
  5.  *
  6.  *    this program does NOT have a Mac-style user interface
  7.  *
  8.  * WARNING WARNING WARNING WARNING WARNING WARNING
  9.  */
  10. #include <stdio.h>
  11. #include "rawfmt.h"
  12.  
  13. #define    MAGIC_C    ((unsigned char)'┼')
  14.  
  15. #define    SFPGET_ID    400
  16. #define    D_Folder    11        /* folder button */
  17.  
  18. int GetSunRast(), TIFFToRaw();
  19.  
  20. int (*getType[])() = {
  21.     GetSunRast,
  22.     TIFFToRaw,
  23.     NULL,
  24. };
  25.  
  26. pascal int dirDlgHook(int item, DialogPtr d) {
  27.     
  28.     if (item == D_Folder)    /* 'use folder' */
  29.         item = 1;            /* getOpen */
  30.     return item;
  31. }
  32.  
  33. main(argc, argv) char **argv; {
  34.     SFReply sf;
  35.     int volNum;
  36.     long dirID, proc;
  37. again:
  38.     printf(":\n");    /* open 'console' window */    
  39.     
  40.     SFPGetFile(0x00600060, "", 0L, 1, "", dirDlgHook, &sf, SFPGET_ID, 0L);
  41.     if (!sf.good)
  42.         return;
  43.         
  44.     if (sf.fName[0] != 0) {        /* this _cannot_ happen since no typeList is given */
  45.         fprintf(stderr,"Choose a directory\n");
  46.         goto again;
  47.     }
  48.     HGetVol(NULL, &volNum, &dirID);
  49.     dirID = sf.fType;        /* replace with that chosen by user */
  50.  
  51.     scanDir(volNum, dirID);
  52.     
  53.     printf("%20c",' ');    /* blank last line */
  54. }
  55.  
  56. /* scan globals */
  57. HFileInfo    h;
  58. Str255 fName;
  59.  
  60. scanDir(int volNum, long dirID)
  61. {
  62.     int index=1;
  63.     
  64.     h.ioNamePtr = fName;
  65.     h.ioVRefNum = volNum;
  66.  
  67.     for (;;) {
  68.         h.ioFDirIndex = index++;
  69.         h.ioDirID = dirID;
  70.         if (PBGetCatInfo(&h, FALSE) != noErr) {
  71.             if (h.ioResult != fnfErr) {        /* end of folder */
  72.                 PtoCstr((char *)fName);
  73.                 fprintf(stderr,"%s: PBGetCatInfo = %d\n",fName,h.ioResult);
  74.             }
  75.             return;
  76.         }
  77.         /* recursively descend directory hierarchy */
  78.         if ((h.ioFlAttrib & ioDirMask))
  79.             scanDir(volNum, h.ioDirID);
  80.         else {
  81.             h.ioDirID = dirID;        /* fudge back parent's dirID */
  82.             Convert(&h);
  83.         }
  84.     }
  85. }
  86.  
  87. Convert(HFileInfo *hp)
  88. {
  89.     raw_t image;
  90.     int i, done=0;
  91.  
  92.     PtoCstr((char *)hp->ioNamePtr);
  93.     printf("%-20.20s\r",hp->ioNamePtr);
  94.     CtoPstr((char *)hp->ioNamePtr);
  95.  
  96.     /* skip already processed files and files with no data fork */
  97.     if ((unsigned char)hp->ioNamePtr[hp->ioNamePtr[0]] == MAGIC_C ||
  98.             h.ioFlLgLen == 0L)
  99.         return;
  100.         
  101.     /*
  102.      * call each getType routine to see if it recognizes the file
  103.      *  (more efficient approach would be to read the first chunk of the file once
  104.      *   and have 'validate' entry points for each type).
  105.      */
  106.     image.data = NULL;
  107.     for (i=0; !done && getType[i]; i++) {
  108.         if ((*getType[i])(hp, &image) == TRUE) {
  109.             /* change name to 'NAME┼' */
  110.             hp->ioNamePtr[0]++;
  111.             hp->ioNamePtr[hp->ioNamePtr[0]] = MAGIC_C;
  112.             PtoCstr((char *)hp->ioNamePtr);
  113.             printf("  Making: %s\n",hp->ioNamePtr);
  114.             CtoPstr((char *)hp->ioNamePtr);
  115.  
  116.             RawToSCMI(hp, &image);
  117.             done = 1;
  118.         }
  119.         if (image.data) {
  120.             DisposPtr(image.data);
  121.             image.data = NULL;
  122.         }
  123.     }
  124. }